<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>step4</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
  <link rel="stylesheet" href="../css/public.css" media="all">
</head>

<body>
  <div class="layuimini-container">
    <div class="layuimini-main">
      <div class="layui-form layuimini-form">
        <div class="layui-form-item">
          <label class="layui-form-label required">申报编号：</label>
          <div class="layui-input-block">
            <input type="text" disabled id="declare_num" name="declare_num" lay-verify="required" lay-reqtext="申报编号不能为空" placeholder="请输入申报编号" value="" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">申报类型：</label>
          <div class="layui-input-block layui-form" lay-filter="selectFilter">
            <select disabled id="declare_type" name="declare_type">
              <option value="固定资产">固定资产</option>
              <option value="首台套">首台套</option>
            </select>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label required">申报标题：</label>
          <div class="layui-input-block">
            <input disabled type="text" id="declare_title" name="declare_title" lay-verify="required" lay-reqtext="申报标题不能为空" placeholder="请输入申报标题" value="" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label required">环节状态：</label>
          <div class="layui-input-block">
            <input disabled type="text" id="link_status" name="link_status" lay-verify="required" lay-reqtext="申报标题不能为空" placeholder="请输入申报标题" value="" class="layui-input">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label required">申报时间：</label>
          <div class="layui-input-block">
            <input disabled type="text" id="declaration_time" name="declaration_time" value="" class="layui-input">
          </div>
        </div>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
          <legend>申报指南：</legend>
        </fieldset>
        <table class="layui-hide" id="table_step2_2" lay-filter="currentTableFilter_step2"></table>
        <!-- step-3 -->
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
          <legend>复核申报指南：</legend>
        </fieldset>
        <textarea disabled id="check_application_guide" name="check_application_guide" style="width: 50%;margin-left: 36px;" rows="10" cols="10" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
        <!-- step-4 -->
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
          <legend>项目申报及复核：
            <button type="button" class="layui-btn layui-btn-primary" id="upload_step1">
              <i class="layui-icon">&#xe67c;</i>数据导入
            </button>
            <legend>
        </fieldset>
        <!-- table1 -->
        <table class="layui-hide" id="table_step4_1" lay-filter="currentTableFilter_step4_1"></table>
        <!-- table2 -->
        <button type="button" class="layui-btn layui-btn-primary" id="upload_step2">
          <i class="layui-icon">&#xe67c;</i>附件上传
        </button>
        <table class="layui-hide" id="table_step4_2" lay-filter="currentTableFilter_step4_2"></table>
        <!-- step-4 -->
        <!-- step-5 -->
<!--        <div class="layui-tab">-->
<!--          <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">-->
<!--            <legend>项目复核：</legend>-->
<!--          </fieldset>-->
<!--          <button type="button" class="layui-btn layui-btn-primary" id="upload_step5">-->
<!--            <i class="layui-icon">&#xe67c;</i>附件上传-->
<!--          </button>-->
<!--          <div class="layui-tab-content">-->
<!--            <div class="layui-tab-item layui-show">-->
<!--              <table class="layui-hide" id="table_step5_1" lay-filter="currentTableFilter_step5"></table>-->
<!--            </div>-->
<!--          </div>-->
<!--        </div>-->
        <!-- step-5 -->
        <div class="layui-form-item">
          <div style="text-align:center">
            <button class="layui-btn layui-btn-primary" lay-submit lay-filter="drop" id="stop">驳回</button>
            <button class="layui-btn layui-btn-normal" id="report">提报</button>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script type="text/html" id="currentTableBar_step2">
    <a class="layui-btn layui-btn-xs layui-btn data-count-handle" lay-event="download">下载</a>
  </script>
  <script type="text/html" id="currentTableBar_step4">
    <a class="layui-btn layui-btn-xs layui-btn data-count-handle" lay-event="download">下载</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger data-count-handle deletea" lay-event="delete">删除</a>
  </script>
  <script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
  <script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
  <script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
  <script src="../js/ManualPaging.js"></script>
  <script src="../js/util.js"></script>
  <script>
    if (!localStorage.getItem("userName")) {
      window.location = './login-1.html';
    }
    layui.use(['form', 'table', 'laydate', 'upload', 'miniTab'], function() {
      var $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        laydate = layui.laydate,
        upload = layui.upload,
        miniTab = layui.miniTab

      // 日期组件
      laydate.render({
        elem: '#declaration_time' //指定元素
      });

      let url = 'pro/queryJmDeclareByTaskID'
      let param = {
        taskID: getQueryVariable('id') // 获取url参数
      }
      if (getQueryVariable('type') === '2') {
        url = 'pro/queryJmDeclareByProcessInstanceID'
        param = {
          processInstanceID: getQueryVariable('id')
        }
        // TODO 删除上传，删除按钮
        $("#report").remove();
        $("#upload_step1").remove();
        $("#stop").remove();
        $("#upload_step2").remove();

      }
      // 获取数据
      $.ajax({
        url: publicurl + url,
        type: 'GET',
        data: param,
        dataType: 'text',
        success: function(result) {
          //表单初始赋值
          if (Object.prototype.toString.call(result) == "[object String]") {
            result = JSON.parse(result)
          }
          if (result.obj.declare) {
            // $('#declare_type').attr('value', result.obj.declare.declare_type);
            $("#declare_type").find("option[value='" + result.obj.declare.declare_type + "']").attr("selected", true);
            form.render('select', 'selectFilter');
            // $('#declare_type').val(result.obj.declare.declare_type);
            $('#check_application_guide').val(result.obj.declare.check_application_guide);
            $("input[name='declare_num']").val(result.obj.declare.declare_num);
            $("input[name='declare_title']").val(result.obj.declare.declare_title);
            $("input[name='link_status']").val(decodeURI(getQueryVariable('name')));
            $("input[name='declaration_time']").val(result.obj.declare.declaration_time);
          }
          // 表格初始值
          let params = {
            id: '#table_step2_2',
            data: 'step2',
            tool: '#currentTableBar_step2',
            table,
            result
          }

          renderTable(params)
          // table_step4_1
          table.render({
            elem: '#table_step4_1',
            defaultToolbar: [''],
            data: result.obj['allOrderPresent'] || null,
            cols: [
              [{
                field: 'enterpriseName',
                width: '10%',
                title: '企业（单位）名称',
                align: "center"
              },
              {
                field: 'area',
                width: '10%',
                title: '所属区、县（市）',
                align: "center"
              },
              {
                field: 'proName',
                width: '10%',
                title: '项目名称',
                align: "center"
              },
              {
                field: 'proType',
                width: '10%',
                title: '项目类别',
                align: "center"
              },
              {
                field: 'filingDept',
                width: '10%',
                title: '备案部门',
                align: "center"
              },
              {
                field: 'contractAmount',
                width: '10%',
                title: '实际投资额',
                align: "center"
              },
              {
                field: 'plannedCompletionTime',
                width: '10%',
                title: '计划完成时间',
                align: "center"
              },
              {
                field: 'concacts',
                width: '10%',
                title: '联系人',
                align: "center"
              },
              {
                field: 'phone',
                width: '10%',
                title: '手机',
                align: "center"
              }]
            ],
            id: 'table_step4_1',
            page: false,
            skin: 'line',
            done: function(res, curr, count) {}
          });

          renderTable({
            id: '#table_step4_2',
            data: 'step4',
            tool: '#currentTableBar_step4',
            table,
            result
          });
          // 表格初始值
          renderTable({
            id: '#table_step5_1',
            data: 'step5',
            tool: '#currentTableBar_step5',
            table,
            result
          })
          // 删除 删除按钮
          if (getQueryVariable('type') === '2') {
            $("a").remove(".deletea");
          }
        },
        error: function(err) {
          console.log(err)
        }
      });
      // 下载和删除
      table.on('tool(currentTableFilter_step2)', function(obj) {
        downloadOrDelete(obj)
      });

      table.on('tool(currentTableFilter_step4_1)', function(obj) {
        downloadOrDelete(obj)
      });

      table.on('tool(currentTableFilter_step4_2)', function(obj) {
        downloadOrDelete(obj)
      });

      //驳回
      $("#stop").click(function() {
        layer.open({
          id:1,
          type: 1,
          title:'请输入驳回意见',
          style: 'width:100%;height:auto;',
          content: "<div style='display:flex;justify-content:center;padding:20px'><textarea id='area' style='width:800px;height:135px;'></textarea></div>",
          btn:['保存','取消'],
          yes:function (index,layero) {
            localStorage.setItem("TBaoID", 1);
            let tibao =localStorage.getItem("TBaoID");
            console.log(tibao);
            //获取输入框里面的值
            var rejectComment =  $("#area").val();
            var param = {
              taskId: getQueryVariable('id'),
              rejectComment: rejectComment
            };
            $.ajax({
              type: "post",
              url: '' + publicurl + 'pro/reject',
              async: false,
              data: param,
              // headers: {'Content-Type': 'application/json'},
              success: function (res) {
                var ele = $(".layuimini-tab .layui-tab-title li.layui-this", parent.document);
                if (ele.length > 0) {
                  var layId = $(ele[0]).attr('lay-id');
                  miniTab.openNewTabByIframe({
                    href:"page/ToDoTasks.html",
                    title:"代办任务",
                  });
                  miniTab.delete(layId, true);
                }

                // window.location.reload()
                //location.reload()
              },
              error: function (request) {
                layer.alert(request.responseJSON.obj, {
                  icon: 2,
                  title: "提示"
                });
              },

            })
          },
          no:function (index,layero) {
            layer.close(index);
          }
        })
      });

      // 提报
      $("#report").click(function() {

        if ($(".layui-table-body.layui-table-main")[1].innerText == "无数据") {
          layer.open({
            content: '请导入数据'
          });
        } else if ($(".layui-table-body.layui-table-main")[2].innerText == "无数据") {
          layer.open({
            content: '请上传文件'
          });
        }
       /* else if ($(".layui-table-body.layui-table-main")[3].innerText == "无数据") {
          layer.open({
            content: '请上传文件'
          });
        } */
        else {
          localStorage.setItem("TBaoID", 1);
          $.ajax({
            type: "post",
            url: '' + publicurl + 'task/completeTask',
            async: false,
            data: JSON.stringify({
              declaration_time: $('#declaration_time').val(),
              link_status: $('#link_status').val(),
              declare_title: $('#declare_title').val(),
              declare_type: $('#declare_type').val(),
              declare_num: $('#declare_num').val(),
              taskID: getQueryVariable('id'),
              isSuccess: "true",
              check_application_guide: $('#check_application_guide').val()
            }),
            headers: { 'Content-Type': 'application/json' },
            success: function(res) {
              //关闭当前页面并且切换到ToDoTasks页
              var ele = $(".layuimini-tab .layui-tab-title li.layui-this", parent.document);
              if (ele.length > 0) {
                var layId = $(ele[0]).attr('lay-id');
                miniTab.openNewTabByIframe({
                  href:"page/ToDoTasks.html",
                  title:"代办任务",
                });
                miniTab.delete(layId, true);
              }
            },
            error: function(request) {
              layer.alert(request.responseJSON.obj, {
                icon: 2,
                title: "提示"
              });
            }
          });
        }
      })

      // 文件上传1 大表格
      var uploadInst = upload.render({
        elem: '#upload_step1', //绑定元素  
        url: '/pro/uploadProRes/', //上传接口    
        data: {
          taskID: getQueryVariable('id')
        },
        done: function(res) {
          //上传完毕回调
          layer.open({
            content: '上传成功',
            time: 1500
          });
          setTimeout(() => {
            window.location.reload()
          }, 1500)
        },
        error: function() {
          //请求异常回调
          layer.open({
            content: '上传失败',
            time: 1500
          });
          setTimeout(() => {
            window.location.reload()
          }, 1500)
        },
        accept: 'file'
      });

      // 文件上传2
      var uploadInst = upload.render({
        elem: '#upload_step2', //绑定元素  
        url: '/pro/uploadFile/', //上传接口   
        data: {
          taskID: getQueryVariable('id')
        },
        done: function(res) {
          //上传完毕回调
          layer.open({
            content: '上传成功',
            time: 1500
          });
          setTimeout(() => {
            window.location.reload()
          }, 1500)
        },
        error: function() {
          //请求异常回调
          layer.open({
            content: '上传失败',
            time: 1500
          });
          setTimeout(() => {
            window.location.reload()
          }, 1500)
        },
        accept: 'file'
      });
      // // 文件上传5
      // var uploadInst = upload.render({
      //   elem: '#upload_step5', //绑定元素
      //   url: '/pro/uploadFile/', //上传接口
      //   data: {
      //     taskID: getQueryVariable('id')
      //   },
      //   done: function(res) {
      //     //上传完毕回调
      //     layer.open({
      //       content: '上传成功',
      //       time: 1500
      //     });
      //     // 上传成功后重新渲染表格
      //     $.ajax({
      //       url: publicurl + 'pro/queryJmDeclareByTaskID',
      //       type: 'GET',
      //       data: {
      //         taskID: getQueryVariable('id') // 获取url参数
      //       },
      //       dataType: 'text',
      //       success: function(result) {
      //         if (Object.prototype.toString.call(result) == "[object String]") {
      //           result = JSON.parse(result)
      //         }
      //         renderTable({
      //           id: '#table_step5_1',
      //           data: 'step5',
      //           tool: '#currentTableBar_step5',
      //           table,
      //           result
      //         })
      //       },
      //       error: function(err) {
      //         console.log(err)
      //       }
      //     });
      //   },
      //   error: function() {
      //     //请求异常回调
      //     layer.open({
      //       content: '上传失败',
      //       time: 1500
      //     });
      //     setTimeout(() => {
      //       window.location.reload()
      //     }, 1500)
      //   },
      //   accept: 'file'
      // });

    });
  </script>
</body>

</html>